package com.baidu.bas.core.query;

import com.baidu.bas.annotation.config.QueryExpression;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author aomo
 */
@Data
@NoArgsConstructor
public class Condition implements Serializable {

    private String key;
    /**
     * 支持多种类型
     */
    private Object value;

    private transient QueryExpression operator = QueryExpression.EQ;

    public boolean isComplex() {
        return key!=null && key.split("\\.").length==2;
    }

    public String getParamKey(){
        if(isComplex()){
            return key.replaceAll("\\.","___");
        }else{
            return key;
        }
    }

    public Condition(String key, Object value, QueryExpression operator) {
        this.key = key;
        this.value = value;
        this.operator = operator;
    }

    public Condition(String key, Object value) {
        this.key = key;
        this.value = value;
    }

}
